# @Filename:    Sample1-add
# @Author:      王佳伟
# @Time:        2025-02-28 9:25
# @Describe:    文件内容统计 - 统计文件中的行数、单词数和字符数
import unittest
from datetime import datetime


def count_lines_words_chars(filename):
    with open(filename, "r") as file:
        content = file.read()
        lines = content.count("\n") + 1
        words = len(content.split())
        chars = len(content)
    return lines, words, chars


class TestFileStats(unittest.TestCase):
    def test_count_lines_words_chars(self):
        filename = "test.txt"
        with open(filename, "w") as file:
            file.write("Hello World\n")
            file.write("This is a test.\n")
        lines, words, chars = count_lines_words_chars(filename)
        self.assertEqual(lines, 3)
        self.assertEqual(words, 6)
        self.assertEqual(chars, 28)


if __name__ == '__main__':
    unittest.main()
